'use strict';
const db = uniCloud.database();
exports.main = async (event, context) => {
	const uniIdToken = event.uniIdToken
	if (!uniIdToken) {
		return {
			code: 1002,
			desc: '您还没有登录，禁止访问'
		}
	}
	const params = event.params
	let uid = params.uid || ''
	if (!uid) {
		return {
			code: 2,
			desc: '没有检测到 uid 参数'
		}
	}
	let userinfo = await db.collection('uni-id-users').doc(uid).get();
	if (userinfo.data.length === 0) {
		return {
			code: 2,
			desc: '未查询到用户信息'
		}
	}

	let project = await db.collection('db-project-list').where({
		user_id: uid
	}).get()

	//返回数据给客户端
	return {
		code:0,
		lists:project.data
	}
};
